package cn.edu.ujn.boot.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.edu.ujn.boot.po.User;
import cn.edu.ujn.boot.service.ICustomerService;
import cn.edu.ujn.boot.service.IUserService;

/**
 * 
 * 用户控制器类
 * 
 * @author XInitia
 *
 */
@Controller
@RequestMapping("/user")
public class UserController {
	@Autowired
	private IUserService userService;

	@Autowired
	private ICustomerService customerService;

	/**
	 * 接收用户登录请求信息
	 * @param user
	 * @param session
	 * @param model
	 * @return
	 */
	@RequestMapping("/login.action")
	public String login(User user, HttpSession session, Model model) {
		User editUser;
		try {
			//通过账号密码查询用户
			editUser = userService.login(user);
			//将接收的用户添加到Session
			session.setAttribute("user", editUser);
		} catch (Exception e) { //若产生错误，则将错误信息添加到Model
			model.addAttribute("error_msg", e.getMessage());
			//返回登录页面
			return "login";
		}
		//成功则跳转到list页面
		return "list";
	}
	
	//用于跳转到login页面
	@RequestMapping("/gologin")
	public String gologin() {
		return "login";
	}

}
